﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Bus.Bll;
using Bus.Model;

public partial class admin_cz : System.Web.UI.Page
{
    protected tb_custom cusBll = new tb_custom();
    protected tb_cost costbll = new tb_cost();
    protected CostModel cm = null;
    protected LogModel lm = null;
    protected CustomModel cusM = null;
    protected tb_log logbll = new tb_log();
    protected int cid;
    protected void Page_Load(object sender, EventArgs e)
    {
        cid = int.Parse(Request.QueryString["id"].ToString());
        if (!IsPostBack)
        {
            InitcusInfo();
        }
    }
    private void InitcusInfo()
    {
        try
        {
            cusM = new CustomModel();
            cusM = cusBll.GetModel(cid);
            cm = new CostModel();
            cm = costbll.GetModel(cid);
            cusname.Text = cusM.cname;
            if (cusM.ctype == 0)
                custp.Text = "老年人";
            if (cusM.ctype == 1)
                custp.Text = "成年人";
            if (cusM.ctype == 2)
                custp.Text = "学生";
            cuskd.Text = cusM.Nmcrad;
            cusxy.Text = cm.money.ToString();
        }
        catch (Exception e)
        {
        }

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {
            if (je.Text == string.Empty)
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('充值金额不能为空！');</script>");
                return;
            }
            //产额充值
            int f = Bus.Dal.DbHelperSQL.ExecuteSql("update tb_cost set costtime='"+DateTime .Now+"' ,m1='充值金额:" + je.Text + "', [money]=[money]+" + decimal.Parse(je.Text) + " where id=" + cid);
            if (f > 0)
            {
                lm = new LogModel();
                lm.userid = cid;
                lm.op = "充值";
                lm.memo = "充值" + je.Text;
                lm.opdate = DateTime.Now;
                logbll.Add(lm);//记录日志
                if (cusxy.Text == "")
                {
                    cusxy.Text = Math.Round(decimal.Parse(je.Text), 2).ToString();
                }
                else
                {
                    cusxy.Text = (decimal.Parse(cusxy.Text) + Math.Round(decimal.Parse(je.Text), 2)).ToString();
                }
                Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('充值【" + je.Text + "】元成功！');</script>");
            }
            else
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('充值【" + je.Text + "】元失败！');</script>");
            }
        }
        catch (Exception ee) { }
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        Response.Redirect("adminCus.aspx");
    }
}
